package com.wut.clock.controller;

import com.wut.clock.aop.log.BusinessType;
import com.wut.clock.aop.log.Log;
import com.wut.clock.common.api.CommonResult;
import com.wut.clock.service.ICommentService;
import com.wut.clock.vo.admin.CommentVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: yuwei
 * @Date: 2022/5/31 20:32
 * @Description: 评论模块
 */

@Api(value = "评论管理",tags = {"评论管理"})
@RestController
@RequestMapping("/comment")
@RequiredArgsConstructor
public class CommentController {

    private final ICommentService commentService;

    @ApiOperation("删除评论")
    @PostMapping("/deleteComment/{commentId}")
    @Log(title = "删除评论",businessType = BusinessType.DELETE)
    @RequiresPermissions("am:comment:delete")
    public CommonResult<String> deleteComment(@PathVariable Integer commentId) {
        commentService.deleteComment(commentId);
        return CommonResult.success();
    }


    @ApiOperation("审核评论")
    @PostMapping("/review/{commentId}")
    @Log(title = "审核评论",businessType = BusinessType.UPDATE)
    @RequiresPermissions("am:comment:update")
    public CommonResult<String> updateCommentsReview(@PathVariable Integer commentId) {
        commentService.updateCommentsReview(commentId);
        return CommonResult.success();
    }

    @ApiOperation("查看评论列表")
    @GetMapping("/getComments")
    @RequiresPermissions("am:comment:query")
    public CommonResult getCommentTreeList(
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(value = "nickname", required = false) String nickname,
            @RequestParam(value = "status", required = false) Integer status) {
        List<CommentVo> commentList = commentService.getCommentTreeList(pageNum,pageSize,nickname,status);
        return CommonResult.success(commentList);
    }
}
